package cn.gzsxt.dao.impl;

import java.util.List;

import com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException;

import cn.gzsxt.dao.DelayApplyDao;
import cn.gzsxt.po.DelayApplyDetail;
import cn.gzsxt.po.PageOut;

public class DelayApplyDaoImpl extends MyBaseDaoImpl implements DelayApplyDao {

	@Override
	public List<DelayApplyDetail> getSelectRows(PageOut page) {
		String sql = getSql(page);
		return super.getSelectRows(DelayApplyDetail.class, sql);
	}

	@Override
	public int updDelay(DelayApplyDetail delay) {
		return super.update(delay);
	}

	@Override
	public int delDelay(Integer id) {
		String sql = "delete from t_delay where taskId = "+id;
		return super.delete(sql);
	}

	@Override
	public int addDelay(DelayApplyDetail delay) {
		try {
			return super.insert(delay);
		} catch (MySQLSyntaxErrorException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return 0;
	}
	
	private String getSql(PageOut page) {
		StringBuffer sql = new StringBuffer();
		sql.append("select * from t_delay");
		String keyWord = page.getKeyword();
		System.out.println(keyWord);
		boolean isKeyword = keyWord != null && keyWord.trim().length() != 0;
		
		if (isKeyword){
			sql.append(" where taskTitle like '%"+keyWord+"%' or clerk like '%"+keyWord+"%' or Status like '%"+keyWord+"%' or taskContent like '%"+keyWord+"%'");
			System.out.println(sql);
		}
		if (page.isPage()){
			sql.append(" limit "+page.getBeginIndex()+","+page.getEndIndex());
		}
		return sql.toString();
	}

	@Override
	public DelayApplyDetail getRow(Integer id) {
		String sql = "select * from t_delay where taskId = "+id;
		return super.getRow(DelayApplyDetail.class, sql);
	}

	@Override
	public int delDelay(String ids) {
		String sql = "delete from t_delay where taskId in ("+ids+")";
		return super.delete(sql);
	}


}
